#pragma once

#include "BaseInc.h"

NAMESPACE_CORE_BEGIN

class CORE_API CValue
{
public:
	CValue()
		: pvVal(nullptr)
	{

	}

	template<typename T>
	CValue(const T & val)
	{
#ifdef _DEBUG
		if(sizeof(T) > sizeof(pvVal))
			throw COverflowException();
#endif 
		T * pVal = (T *)&pvVal;
		*pVal = val;
	}

	template<typename T>
	CValue & operator = (const T & val)
	{
#ifdef _DEBUG
		if(sizeof(T) > sizeof(pvVal))
			throw COverflowException();
#endif 
		T * pVal = (T *)&pvVal;
		*pVal = val;
		return *this;
	}

	template<typename T>
	operator T()
	{
#ifdef _DEBUG
		if(sizeof(T) > sizeof(pvVal))
			throw COverflowException();
#endif 
		T * pVal = (T *)&pvVal;
		return *pVal;
	}

	union
	{
		void * pvVal;

		int_8 * pi8Val;
		int_16 * pi16Val;
		int_32 * pi32Val;
		int_64 * pi64Val;

		uint_8 * pui8Val;
		uint_16 * pui16Val;
		uint_32 * pui32Val;
		uint_64 * pui64Val;

		char_8 * pc8Val;
		char_16 * pc16Val;

		int_8 i8Val;
		int_16 i16Val;
		int_32 i32Val;
		//int_64 i64Val;

		uint_8 ui8Val;
		uint_16 ui16Val;
		uint_32 ui32Val;
		//uint_64 ui64Val;

		char_8 c8Val;
		char_16 c16Val;
	};

};

NAMESPACE_CORE_END
